import React, { useState, useEffect } from 'react'
import axios from 'axios'

const Preview = (props) => {
  // console.log(props) //函数式组件从函数的形参中就能拿到属性
  const [Price, setPrice] = useState("")

  useEffect(() => {
    // 地址/cnode/user/alsotang && /topic_collect/i5ting
    // http://www.mei.com/appapi/product/getProductPrice/v3?productId=&userLevel=2&type=0
    const fetchData = async () => {
      try {
        const result = await axios.get(`http://www.mei.com/appapi/product/getProductPrice/v3?productId=${props.match.params.id}&userLevel=2&type=0`)
        setPrice(result.data.retDto.price)
      } catch (error) {
        console.log(error)
      }
    };
    // 调用
    fetchData();
    // 销毁回调
    return () => { }
  }, [props])

  return (
    <div>
      <p>魅力惠裙子价格: {Price}</p>
    </div>
  )
}

export default Preview